package com.wjx.jpa.dao;

import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.scheduling.annotation.Async;

import com.wjx.jpa.bean.Student;

public interface StudentDao extends CrudRepository<Student, Integer>{
	List<Student> findByName(String name);
	List<Student> findByNameAndBirthdayOrderByIdDesc(String name,Date Birthday);
	List<Student> findByTeacherId(int tId);//teacher 对象里的id用 Teacher_Id表示
	Page<Student> getByName(String name,Pageable page); //排序分页
	Student findTopByOrderByIdDesc();//按id降序，取第一个
	List<Student> findTop2ByNameOrderByIdDesc(String name);
	@Async
	Future<Student> findById(int id);
	
	@Query("select s from Student s where s.id=?1")
	Student queryById(int id);

	@Modifying
	@Query("update Student set name=?1 where id=?2")
	void updateStuNameById(String name,int id);
	
	@Modifying
	@Query("delete from Student where id=?1")
	void deleteById(int id);
}
